import 'package:flutter/material.dart';

import 'inherited_demo.dart';


class MyApp010 extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Scaffold(
        appBar: AppBar(),
        body: InheritedDemo(),
        // body: MyHomePage(),
      ),
    );
  }
}
//
//class MyHomePage extends StatelessWidget {
//  final String title;
//  MyHomePage({this.title}) {
//    print('构造函数被调用了!');
//  }
//  @override
//  Widget build(BuildContext context) {
//    print('build方法被调用了!');
//    return Center(
//      child: Text(title),
//    );
//  }
//构造函数被调用 > build方法被调用了
// 安卓会调用2次 ，安卓的bug，但是热更只会执行一次
//}

class MyHomePage extends StatefulWidget {
  final String title;
  MyHomePage({this.title}) {
    print('构造函数被调用了!');
  }
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _count = 0;

  _MyHomePageState() {
    print('State构造方法来了!');
  }

  @override
  void initState() {
    print('State的init来了!');
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
//    StatefulElement element = context;
    print('State的build来了!');
    return Column(
      children: <Widget>[
        RaisedButton(
          child: Icon(Icons.add),
          onPressed: () {
            _count++;
            setState(() {});
//            element.markNeedsBuild();
          },
        ),
        Text('$_count'),
      ],
    );
  }

  @override
  void didChangeDependencies() {
    print('didChangeDependencies');
    super.didChangeDependencies();
  }

  //当State对象从渲染树中移出的时候,就会调用!即将销毁!
  @override
  void deactivate() {
    print('deactivate');
    super.deactivate();
  }

  @override
  void dispose() {
    print('State的dispose');
    super.dispose();
  }
}
